// 引入封装好的 post 请求
import post from '../config/post';
import get from '../config/get';

const SPACE_BASE_URL = "api/space";

const TEST_SPACE_URL = SPACE_BASE_URL + '/test';
const CREATE_SPACE_URL = SPACE_BASE_URL + '/create';
const GET_SPACE_PAGE_URL = SPACE_BASE_URL + '/page';

// 创建空间请求函数 (携带 Cookie)
const createSpace = (formData, successCallback, failCallback) => {
    post(
        CREATE_SPACE_URL,
        formData,
        successCallback,
        failCallback,
        {
            'withCredentials': true               // 携带 Cookie
        }
    );
};

// 测试接口请求 (携带 Cookie)
const testSpace = (params, successCallback, failCallback) => {
    get(
        TEST_SPACE_URL,
        params,
        successCallback,
        failCallback,
        { 'withCredentials': true }  // 携带 Cookie
    );
};

// 分页查询请求 (携带 Cookie)
const getSpacePage = (params, successCallback, failCallback) => {
    post(
        GET_SPACE_PAGE_URL,
        params,
        successCallback,
        failCallback,
        {
            'Content-Type': 'application/json',
            'withCredentials': true  // 携带 Cookie
        }
    );
};

export { createSpace, testSpace, getSpacePage };